package com.hadoop.mapreduce.mobilestatistics.bean;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author chenxigu
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MobileTrafficInformation implements WritableComparable {
    /**
     * 时间戳
     */
    private Long time;
    /**
     * 电话号码
     */
    private String phone;
    /**
     * 基站的物理地址
     */
    private String physicalAddress;
    /**
     * 访问网址的 ip
     */
    private String ip;
    /**
     * 网站域名
     */
    private String domainName;
    /**
     * 数据包
     */
    private String data;

    /**
     * 接包数
     */
    private Long receivePackageCount;

    /**
     * 上行 / 传流量
     */
    private Long upstreamDownstreamTraffic;

    /**
     * 下行 / 载流量
     */
    private Long downLinkAmpacity;

    /**
     * 响应码
     */
    private String responseCode;

    @Override
    public String toString() {
        return this.time + "\t" + this.phone + "\t" + physicalAddress + "\t" + this.ip + "\t" + this.domainName + "\t"
                + this.data + "\t" + this.receivePackageCount + "\t" + this.upstreamDownstreamTraffic + "\t" + this.downLinkAmpacity + "\t" + this.responseCode;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(time);
        out.writeUTF(phone);
        out.writeUTF(physicalAddress);
        out.writeUTF(ip);
        out.writeUTF(domainName);
        out.writeUTF(data);
        out.writeLong(receivePackageCount);
        out.writeLong(upstreamDownstreamTraffic);
        out.writeLong(downLinkAmpacity);
        out.writeUTF(responseCode);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.time = in.readLong();
        this.phone = in.readUTF();
        this.physicalAddress = in.readUTF();
        this.ip = in.readUTF();
        this.domainName = in.readUTF();
        this.data = in.readUTF();
        this.receivePackageCount = in.readLong();
        this.upstreamDownstreamTraffic = in.readLong();
        this.downLinkAmpacity = in.readLong();
        this.responseCode = in.readUTF();
    }

    @Override
    public int compareTo(Object o) {
        return 0;
    }
}
